<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>账号列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/public/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/public/layuiadmin/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-col-md12">
        <div class="layui-card">
            <div class="layui-card-body">
                <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                    <div class="layui-form-item">

                        <div class="layui-inline">
                            <label class="layui-form-label">手机号</label>
                            <div class="layui-input-block" style="width: 200px;">
                                <input class="layui-input" name="mobile" placeholder="请输入手机号" autocomplete="off">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">姓名</label>
                            <div class="layui-input-block" style="width: 200px;">
                                <input class="layui-input" name="name" placeholder="请输入姓名" autocomplete="off">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">账号类型</label>
                            <div class="layui-input-block" style="width: 200px;">
                                <select name="type">
                                    <option value="">全部</option>
                                    <option value="0">管理后台账号</option>
                                    <option value="1">商家主账号</option>
                                    <option value="2">商家子账号</option>
                                </select>
                            </div>
                        </div>


                        <div class="layui-inline">
                            <label class="layui-form-label">站点ID</label>
                            <div class="layui-input-block" style="width: 200px;">
                                <input class="layui-input" name="stationId" placeholder="请输入站点ID" autocomplete="off">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">站点名称</label>
                            <div class="layui-input-block" style="width: 300px;">
                                <input class="layui-input" name="stationName" placeholder="请输入站点名称" autocomplete="off">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <button class="layui-btn layuiadmin-btn-useradmin" lay-submit
                                    lay-filter="LAY-search">
                                <i class="layui-icon layui-icon-search layuiadmin-button-btn"> 搜索</i>
                            </button>
                        </div>
                    </div>
                </div>

                <table class="layui-hide" id="test-table-reload" lay-filter="test-table-reload"></table>

                <script type="text/html" id="test-table-reload-toolbar">
                    <button class="layui-btn layui-btn-sm #{if !toolsUtils.checkBtn('/sys/addUser')} layui-hide #{/if}" lay-event="addUser"><i class="layui-icon layui-icon-add-circle-fine"></i>添加账号</button>
                </script>

                <script type="text/html" id="test-table-reload-barDemo">
                     <a class="layui-btn layui-btn-xs #{if !toolsUtils.checkBtn('/sys/editUser')} layui-hide #{/if}" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                     {{#  if(d.invalid == 1){ }}
                     <a class="layui-btn layui-btn-xs #{if !toolsUtils.checkBtn('/merchant/updateInvalid')} layui-hide #{/if}" lay-event="invalid">启用账号</a>
                     {{#  } else { }}
                     <a class="layui-btn layui-btn-xs #{if !toolsUtils.checkBtn('/merchant/updateInvalid')} layui-hide #{/if}" lay-event="valid">停用账号</a>
                     {{#  } }}
                </script>
            </div>
        </div>
    </div>
</div>
<input type="hidden" id="total" value="${total}">
<script src="/public/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/public/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table','utils', 'form'], function(){
        var $ = layui.$,
                table = layui.table,
                form = layui.form,
                admin = layui.admin;

        //监听搜索
        form.on("submit(LAY-search)", function (data) {
            var field = data.field;

            //执行重载
            table.reload('test-table-reload', {
                where: field
            });
        });

        //方法级渲染
        table.render({
            elem: '#test-table-reload'
            ,url: "/sys/getUserList"
            ,toolbar: '#test-table-reload-toolbar'
            ,defaultToolbar:['filter']
            ,cellMinWidth: 80
            ,cols: [[
                {field:'id', title: '账号ID', fixed: true}
                , {field:'mobile', title: '手机号'}
                , {field:'account', title: '账号名称'}
                , {field:'typeName', title: '账号类型'}
                , {field:'roleName', title: '账号角色'}
                , {field:'name', title: '姓名'}
                , {field:'stations', title: '关联站点数'}
                , {field: 'stationNames', title: '关联站点名称', width: 400, templet: function (d) {
                        if (d.stationNames.length > 0) {
                            if (d.stationNames.length === parseInt($("#total").val())) {
                                return "<div>" + "全部" + "</div>";
                            } else {
                                return "<div>" + d.stationNames + "</div>";
                            }
                        } else {
                            return "<div>" + "" + "</div>";
                    }}}
                , {field:'createTime', title: '创建时间',sort: true,templet: function (d) {
                        return "<div>"+layui.toDateString(d.createTime)+"</div>";
                    }}
                , {fixed: 'right', title:'操作', toolbar: '#test-table-reload-barDemo', width:180}
            ]]
            ,page: true
            ,height: 524
        });

        //头工具栏事件
        table.on('toolbar(test-table-reload)', function(obj){
            if(obj.event === 'addUser'){
                window.location.href="/sys/addUser";
            }
        });

        //监听行工具事件
        table.on('tool(test-table-reload)', function (obj) {
                var data = obj.data;
                if (obj.event === 'invalid') {
                    layer.confirm('该账号停止使用状态，是否要启用？', {icon: 7, title: '提示', skin: 'layui-layer-molv', anim: 4}, function () {
                        $.get("/merchant/updateInvalid?id=" + data.id + "&invalid=0", function (result) {
                            if (result.code > 0) {
                                layer.msg(result.msg, {icon: 2});
                            } else {
                                layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                    window.location.reload();
                                });
                            }
                        });
                    });
                } else if (obj.event === 'valid') {
                    layer.confirm('该账号正常使用状态，是否要停用？', {icon: 7, title: '提示', skin: 'layui-layer-molv', anim: 4}, function () {
                        $.get("/merchant/updateInvalid?id=" + data.id + "&invalid=1", function (result) {
                            if (result.code > 0) {
                                layer.msg(result.msg, {icon: 2});
                            } else {
                                layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                    window.location.reload();
                                });
                            }
                        });
                    });
                }else if(obj.event === 'edit'){
                window.location.href="/sys/editUser?id="+data.id;
            }
        });

    });
</script>
</body>
</html>